package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.Admin;
import com.itheima.mapper.AdminMapper;
import com.itheima.mapper.AnnouncementMapper;
import com.itheima.service.db.AdminService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private AnnouncementMapper announcementMapper;


    //根据用户名查询详细信息
    @Override
    public Admin findByUsername(String username) {

        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);

        return adminMapper.selectOne(wrapper);
    }

    //公告列表
    @Override
    public PageBeanVo findAnnouncements(Integer pageNum, Integer pageSize) {
        IPage page = new Page<>(pageNum, pageSize);

        QueryWrapper wrapper = new QueryWrapper();

        page = announcementMapper.selectPage(page, wrapper);

        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }
}
